package docs.cvs.service.logger;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.AfterReturning;

import java.util.Arrays;

public class UserLogger {
    private static final Logger logger = Logger.getLogger(UserLogger.class);
    
    /**
     * 前置增强代码
     * @param joinPoint
     */
    @Before("execution(* service.UserService.*(..))")
    public void before(JoinPoint joinPoint){
        logger.info("调用"+joinPoint.getTarget()+
                "的"+joinPoint.getSignature().getName()+
                "方法。方法入参："+ Arrays.toString(joinPoint.getArgs()));
    }
    
    /**
     * 后置增强代码
     * @param joinPoint
     * @param result
     */
    @AfterReturning(pointcut = "execution(* service.UserService.*(..))",returning = "returnValue")
    public void afterReturning(JoinPoint joinPoint,Object result){
        logger.info("调用方法"+joinPoint.getSignature().getName()+" 方法返回值："+result);
    }
}
